// index.js
const { getAllWheels } = require('../../config/wheels.js')

Page({
  data: {
    wheelList: []
  },

  onLoad() {
    this.loadWheelList()
  },

  onShow() {
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline']
    })
  },

  onShareAppMessage() {
    return {
      title: '转盘助手 - 快来创建你的幸运转盘！',
      path: '/pages/index/index'
    }
  },

  onShareTimeline() {
    return {
      title: '转盘助手 - 快来创建你的幸运转盘！'
    }
  },

  // 加载转盘列表
  loadWheelList() {
    const presetWheels = getAllWheels()
    const savedWheels = wx.getStorageSync('saved_wheels') || []
    
    // 合并预设转盘和已保存的自定义转盘
    const allWheels = [...presetWheels, ...savedWheels]
    
    this.setData({
      wheelList: allWheels
    })
  },

  // 选择转盘
  selectWheel(e) {
    const wheelId = e.currentTarget.dataset.wheelId
    console.log('选择转盘:', wheelId)
    
    wx.navigateTo({
      url: `/pages/wheel/wheel?wheelId=${wheelId}`
    })
  },

  // 创建自定义转盘
  createCustomWheel() {
    wx.navigateTo({
      url: '/pages/wheel/wheel?wheelId=custom'
    })
  }
})